/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ControlEscolar.DAOs;

import com.ControlEscolar.Beans.Professor;
import java.util.ArrayList;


/**
 *
 * @author Listico
 */
public class ProfessorDAO extends AbstractDAO <Professor> {

    @Override
    public void add(Professor professor) throws DAOException {
        String sql = "INSERT INTO professors (professor_name,professor_tel,state)values(\""

                + professor.getProfessor_Name()+"\",\""
                + professor.getProfessor_Tel()+"\",\""
                + professor.getState()+"\")";

        try {
            connection.executeUpdate(sql);
        } catch (Exception ex) {
            throw new DAOException();
        }

    }

    @Override
    public int delete(String condition) throws DAOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int update(Professor professor) throws DAOException {
        try {
            String sql = "UPDATE professors SET " +
                    "professor_name = \"" + professor.getProfessor_Name()
                    + "\", professor_tel=\"" + professor.getProfessor_Tel()
                    +"\", state=\""+professor.getState()
                    + "\" WHERE ID_Professor=" + professor.getId_Professor();

            connection.executeUpdate(sql);
            return 0;
        } catch (Exception ex) {
            throw new DAOException();
             }
    }

    @Override
    public ArrayList<Professor> query() throws DAOException {
        try {
            String sql = "SELECT * FROM professors";
            return connection.executeQuery(sql, Professor.class);

        } catch (Exception ex) {
            ex.printStackTrace();
            throw new DAOException();
        }
    }

     public Professor queryByName(String professorName) throws DAOException {
        try {

            String sql = "SELECT * FROM professors where professor_name = \""+professorName;
            ArrayList<Professor> professorQuery=connection.executeQuery(sql, Professor.class);
           return getSpecificQuery(professorQuery);

        } catch (Exception ex) {
            throw new DAOException();
        }
    }

     public Professor queryByID(int ID_Professor)throws DAOException{
         try {
            String sql = "SELECT * FROM professors where ID_professor = "+ID_Professor;
            ArrayList<Professor> professorQuery=connection.executeQuery(sql, Professor.class);
              return getSpecificQuery(professorQuery);

        } catch (Exception ex) {
            throw new DAOException();
        }
     }
        public Professor queryProfessor(String professorName, String professorTel) throws DAOException {
        try {

            String sql = "SELECT * FROM professors where professor_name = \""+professorName+"\" and professor_tel= \""+professorTel+"\"";
            ArrayList<Professor> professorQuery=connection.executeQuery(sql, Professor.class);
              return getSpecificQuery(professorQuery);

        } catch (Exception ex) {
            ex.printStackTrace();
            throw new DAOException();
        }
    }


}